﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Windows.Forms;
using System.Diagnostics;
using System.Text.RegularExpressions;
using System.Data.OleDb;
using System.IO;
using System.Data;
using SDD;

namespace SDD
{
    class cHttp
    {
        /// <summary>
        /// 抓URL的HTML碼 Default
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        public string dopost(string url)
        {
            string html = "";
            HttpWebRequest req = WebRequest.Create(url) as HttpWebRequest;
            HttpWebResponse res = req.GetResponse() as HttpWebResponse;
            Stream st = res.GetResponseStream();
            StreamReader sr = new StreamReader(st, System.Text.Encoding.Default);

            html = sr.ReadToEnd();

            sr.Close();
            sr.Dispose();
            st.Flush();
            st.Close();
            st.Dispose();
            return html;
        }

        /// <summary>
        /// 抓URL的HTML碼 UTF8
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        public string dopost_UTF8(string url)
        {
            string html = "";
            HttpWebRequest req = WebRequest.Create(url) as HttpWebRequest;
            HttpWebResponse res = req.GetResponse() as HttpWebResponse;
            Stream st = res.GetResponseStream();
            StreamReader sr = new StreamReader(st, System.Text.Encoding.UTF8);

            html = sr.ReadToEnd();

            sr.Close();
            sr.Dispose();
            st.Flush();
            st.Close();
            st.Dispose();
            return html;
        }

        /// <summary>
        /// 抓URL的HTML碼 Big5
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        public string dopost_Big5(string url)
        {
            string html = "";
            HttpWebRequest req = WebRequest.Create(url) as HttpWebRequest;
            HttpWebResponse res = req.GetResponse() as HttpWebResponse;
            Stream st = res.GetResponseStream();
            StreamReader sr = new StreamReader(st, System.Text.Encoding.GetEncoding(950));

            html = sr.ReadToEnd();

            sr.Close();
            sr.Dispose();
            st.Flush();
            st.Close();
            st.Dispose();
            return html;
        }
    
    
    
    
    }
}
